package com.xiaocikuai.smallchunks.service.Transaction;

import com.alibaba.fastjson.JSONObject;
import com.xiaocikuai.smallchunks.entity.Transaction.Address;
import com.xiaocikuai.smallchunks.mapper.Transaction.TransactionMapper;
import com.yl.jms.sdk.JtExpressApi;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;



@Service
public class JTEService {

    @Resource
    private JtExpressApi jtExpressApi;

    @Resource
    private TransactionMapper transactionMapper;

    public static final String addUrl = "http://test-openapi.jtexpress.com.cn/webopenplatformapi/api/order/addOrder";

    public JSONObject addOrder(int aid, String orderId) throws IOException {
        Map<String, Object> map = new HashMap<>();
        Map<String, Object> sender = new HashMap<>();
        Map<String, Object> receiver = new HashMap<>();
        map.put("txlogisticId", orderId);//客户订单号（传客户自己系统的订单号）
        map.put("network", "6539187");//合作网点编码（没有则不传）
        map.put("expressType", "EZ");//快件类型：EZ(标准快递),TYD(兔优达)
        map.put("orderType", "1");//订单类型（有客户编号为月结）1、 散客；2、月结；
        map.put("serviceType", "01");//服务类型 ：02 门店寄件 ； 01 上门取件
        map.put("deliveryType", "03");//派送类型： 06 代收点自提 05 快递柜自提 04 站点自提 03 派送上门
        map.put("goodsType", "1");//支付方式：PP_PM("寄付月结"), CC_CASH("到付现结");
        map.put("weight", "1");

        sender.put("name", "狄仁杰");
        sender.put("mobile", "12345678909");
        sender.put("phone", "");
        sender.put("countryCode", "CHN");
        sender.put("prov", "山东省");
        sender.put("city", "淄博");
        sender.put("area", "沂源县");
        sender.put("address", "E通世界园");
        map.put("sender", sender);

        Address address = transactionMapper.getAddressInfo(aid);
        receiver.put("name", address.getConsignee());
        receiver.put("mobile", address.getTelephone());
        receiver.put("phone", "");
        receiver.put("countryCode", "CHN");
        receiver.put("prov", address.getProv());
        receiver.put("city", address.getCity());
        receiver.put("area", address.getArea());
        receiver.put("address", address.getProv() + address.getCity() + address.getArea() + address.getDelivery());
        map.put("receiver", receiver);
        return jtExpressApi.postByCustom(map, addUrl);
    }






}
